package br.atribuicoes.professor.producaoAcademica

import br.academia.Professor

class BancasDefesasController {

	def scaffold = BancasDefesas

	def save = {
		def bancasDefesasInstance = new BancasDefesas(params)

		Professor professor = Professor.findByUsername(session.user)

		println ("Professor "+professor)
		if (professor){

			if (bancasDefesasInstance.save(flush: true)) {

				ProducaoAcademica producaoAcademica = new ProducaoAcademica()
				producaoAcademica.bancasDefesas = bancasDefesasInstance
				producaoAcademica.dataCadastro = new Date()

				if (producaoAcademica.save(flush: true)){
					professor.addToProducoesAcademica(producaoAcademica)
					flash.message = "${message(code: 'default.created.message', args: [message(code: 'bancasDefesas.label', default: 'Bancas Defesas'), bancasDefesasInstance.id])}"
					redirect(action: "show", id: bancasDefesasInstance.id)
				}else{
					flash.message("ERRO!")
					render(view: "create", model: [bancasDefesasInstance: bancasDefesasInstance])
				}
			}
		}
		else {
			flash.message("Professor Invalido no Sistema!")
			render(view: "create", model: [bancasDefesasInstance: bancasDefesasInstance])
		}
	}
}
